package com.codecorp.cortex_scan;

import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.preference.TwoStatePreference;

import com.example.ht380d4G_jar_demo.R;

@SuppressWarnings("deprecation")
public class SymbologiesActivity extends PreferenceActivity implements
        Preference.OnPreferenceClickListener {

    private Preference mEnableAll;
    private Preference mDisableAll;
    private PreferenceScreen mSymbologies;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Load the XML preferences file
        addPreferencesFromResource(R.xml.symbologies);
        mSymbologies = (PreferenceScreen) getPreferenceScreen().findPreference(
                "symbologies");
        mEnableAll = (Preference) getPreferenceScreen().findPreference(
                "enable_all");
        mEnableAll.setOnPreferenceClickListener(this);
        mDisableAll = (Preference) getPreferenceScreen().findPreference(
                "disable_all");
        mDisableAll.setOnPreferenceClickListener(this);
    }

    @Override
    public boolean onPreferenceClick(Preference preference) {
        if (preference == mEnableAll) {
            // Enable all symbologies. CortexScan will detect the preference
            // change and do the actual work.
            int count = mSymbologies.getPreferenceCount();
            for (int i = 2; i < count; i++) {
                Preference p = mSymbologies.getPreference(i);
                if (p instanceof CheckBoxPreference);
                    ((CheckBoxPreference) p).setChecked(true);
            }
            return true;
        } else if (preference == mDisableAll) {
            // Disable all symbologies. CortexScan will detect the preference
            // change and do the actual work.
            int count = mSymbologies.getPreferenceCount();
            for (int i = 2; i < count; i++) {
                Preference p = mSymbologies.getPreference(i);
                if (p instanceof CheckBoxPreference);
                    ((CheckBoxPreference) p).setChecked(false);
            }
            return true;
        }
        return false;
    }
}
